package leetcode;

import java.util.HashSet;

public class Q0202 {
    public boolean isHappy(int n) {
        HashSet<Integer> set = new HashSet<>();
        while (true) {
            if (n == 1) return true;
            int sum = 0;
            while (n != 0) {
                sum += (n % 10) * (n % 10);
                n /= 10;
            }
            if (set.contains(sum)) return false;
            set.add(sum);
            n = sum;
        }
    }

    public static void main(String[] args) {
        Q0202 sl = new Q0202();
        sl.isHappy(19);
    }
}
